github.com/nvkalinin/business-calendar@v1.0.2-0.20220515154925-e7df8a3d0c34/cmd/sync_test.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/stretchr/testify/assert" 6 "github.com/stretchr/testify/require" 7 "testing" 8 "time" 9 ) 10 11 func TestSyncCmd(t *testing.T) { 12 _, a, port := newApp(t, nil) 13 go a.run() 14 defer a.shutdown() 15 waitForHTTP(port) 16 17 cmd := newSyncCmd(port, []int{2021, 2022}) 18 err := cmd.Execute([]string{}) 19 require.NoError(t, err) 20 21 // После синхронизации должен быть доступен календарь. 22 23 status, json := getBody(t, fmt.Sprintf("http://localhost:%d/api/cal/2021/01/01", port)) 24 expJson := `{ 25 "weekDay": "fri", 26 "working": true, 27 "type": "normal" 28 }` 29 assert.Equal(t, 200, status) 30 assert.JSONEq(t, expJson, json) 31 32 status, json = getBody(t, fmt.Sprintf("http://localhost:%d/api/cal/2022/04/20", port)) 33 expJson = `{ 34 "weekDay": "wed", 35 "working": true, 36 "type": "normal" 37 }` 38 assert.Equal(t, 200, status) 39 assert.JSONEq(t, expJson, json) 40 } 41 42 func newSyncCmd(port int, y []int) *Sync { 43 return &Sync{ 44 ServerUrl: fmt.Sprintf("http://localhost:%d", port), 45 AdminPasswd: "pass", 46 Timeout: 60 * time.Second, 47 Years: y, 48 } 49 }