github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/cmd/state-svc/internal/rtwatcher/entry_test.go (about) 1 package rtwatcher 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/ActiveState/cli/internal/analytics/dimensions" 8 ) 9 10 func Test_entry_IsRunning(t *testing.T) { 11 type fields struct { 12 PID int 13 Exec string 14 Dims *dimensions.Values 15 } 16 tests := []struct { 17 name string 18 fields fields 19 want bool 20 wantErr bool 21 }{ 22 { 23 name: "running", 24 fields: fields{ 25 PID: os.Getpid(), 26 Exec: os.Args[0], 27 }, 28 want: true, 29 wantErr: false, 30 }, 31 { 32 name: "not running", 33 fields: fields{ 34 PID: 123, 35 Exec: "not running", 36 }, 37 want: false, 38 wantErr: false, 39 }, 40 } 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 e := entry{ 44 PID: tt.fields.PID, 45 Exec: tt.fields.Exec, 46 Dims: tt.fields.Dims, 47 } 48 got, err := e.IsRunning() 49 if (err != nil) != tt.wantErr { 50 t.Errorf("IsRunning() error = %v, wantErr %v", err, tt.wantErr) 51 return 52 } 53 if got != tt.want { 54 t.Errorf("IsRunning() got = %v, want %v", got, tt.want) 55 } 56 }) 57 } 58 }