func TestProcessesListWithDetached(t *testing.T) { models.TestProvider = &provider.TestProvider{ Instances: []structs.Instance{ structs.Instance{}, structs.Instance{}, structs.Instance{}, }, } // setup expectations on current provider models.TestProvider.On("InstanceList").Return(models.TestProvider.Instances, nil) os.Setenv("RACK", "convox-test") os.Setenv("CLUSTER", "convox-test-cluster") aws := test.StubAws( test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.ListContainerInstancesCycle("convox-test-cluster"), test.DescribeContainerInstancesCycle("convox-test-cluster"), test.DescribeInstancesCycle(), test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"), test.DescribeTasksCycle("convox-test-cluster"), test.ListTasksOneoffCycle("convox-test-cluster"), test.DescribeTasksOneoffCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.DescribeServicesCycle("convox-test-cluster"), ) defer aws.Close() docker := test.StubDocker( // query for every ECS task to get docker id, command, created test.ListECSContainersCycle(), test.ListECSOneoffContainersCycle(), // query every instance for one-off containers test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersEmptyCycle(), ) defer docker.Close() body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", url.Values{}) var resp client.Processes err := json.Unmarshal([]byte(body), &resp) if assert.Nil(t, err) { assert.Equal(t, 2, len(resp)) assert.Equal(t, "echo 1", resp[0].Command) assert.Equal(t, "/bin/sh -c yes", resp[1].Command) } }
func TestProcessesList(t *testing.T) { // set current provider models.TestProvider = &provider.TestProvider{ Instances: []structs.Instance{ structs.Instance{}, structs.Instance{}, structs.Instance{}, }, } // setup expectations on current provider models.TestProvider.On("InstanceList").Return(models.TestProvider.Instances, nil) aws := test.StubAws( test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.ListContainerInstancesCycle("convox-test-cluster"), test.DescribeContainerInstancesCycle("convox-test-cluster"), test.DescribeInstancesCycle(), test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"), test.DescribeTasksCycle("convox-test-cluster"), test.ListTasksOneoffEmptyCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.DescribeServicesCycle("convox-test-cluster"), ) defer aws.Close() docker := test.StubDocker( // query for every ECS task to get docker id, command, created test.ListECSContainersCycle(), // query every instance for one-off containers test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersEmptyCycle(), // query for every container to get CPU and Memory stats test.StatsCycle(), ) defer docker.Close() v := url.Values{} v.Add("stats", "true") body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", v) var resp client.Processes err := json.Unmarshal([]byte(body), &resp) if assert.Nil(t, err) { assert.Equal(t, 1, len(resp)) assert.Equal(t, 0.0974, resp[0].Memory) } }
func TestProcessesListWithAttached(t *testing.T) { os.Setenv("RACK", "convox-test") os.Setenv("CLUSTER", "convox-test-cluster") aws := test.StubAws( test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.ListContainerInstancesCycle("convox-test-cluster"), test.DescribeContainerInstancesCycle("convox-test-cluster"), test.DescribeInstancesCycle(), test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"), test.DescribeTasksCycle("convox-test-cluster"), test.ListTasksOneoffEmptyCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.DescribeServicesCycle("convox-test-cluster"), ) defer aws.Close() docker := test.StubDocker( // query for every ECS task to get docker id, command, created test.ListECSContainersCycle(), // query every instance for one-off containers test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersCycle("79bd711b1756"), test.InspectCycle("79bd711b1756"), test.ListOneoffContainersEmptyCycle(), ) defer docker.Close() body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", url.Values{}) var resp client.Processes err := json.Unmarshal([]byte(body), &resp) if assert.Nil(t, err) { assert.Equal(t, 2, len(resp)) assert.Equal(t, "/bin/sh -c bash", resp[0].Command) assert.Equal(t, "echo 1", resp[1].Command) } }
func TestProcessesList(t *testing.T) { os.Setenv("RACK", "convox-test") os.Setenv("CLUSTER", "convox-test-cluster") os.Setenv("TEST", "true") aws := test.StubAws( test.DescribeAppStackCycle("myapp-staging"), test.DescribeAppStackCycle("myapp-staging"), test.ListTasksCycle("convox-test-cluster"), test.DescribeTasksCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeContainerInstancesFilteredCycle("convox-test-cluster"), test.DescribeInstancesFilteredCycle(), test.DescribeAppStackResourcesCycle("myapp-staging"), test.DescribeServicesCycle("convox-test-cluster"), test.ListContainerInstancesCycle("convox-test-cluster"), test.DescribeContainerInstancesCycle("convox-test-cluster"), test.DescribeInstancesCycle(), ) defer aws.Close() docker := test.StubDocker( test.ListContainersCycle(), test.ListConvoxContainersCycle(), test.ListConvoxContainersCycle(), test.ListConvoxContainersCycle(), test.StatsCycle(), ) defer docker.Close() // Note: there is a synchronization issue inside the Docker Stats fanout // So while the StatsCycle does work sometimes, the test bypasses stats for now v := url.Values{} v.Add("stats", "false") body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", v) var resp client.Processes err := json.Unmarshal([]byte(body), &resp) if assert.Nil(t, err) { assert.Equal(t, 1, len(resp)) assert.Equal(t, 0.0, resp[0].Memory) } }
func TestProcessesListWithAttached(t *testing.T) { // set current provider testProvider := &provider.TestProviderRunner{ Instances: []structs.Instance{ structs.Instance{}, structs.Instance{}, structs.Instance{}, }, } provider.CurrentProvider = testProvider defer func() { //TODO: remove: as we arent updating all tests we need tos et current provider back to a //clean default one (I miss rspec before) provider.CurrentProvider = new(provider.TestProviderRunner) }() // setup expectations on current provider testProvider.On("InstanceList").Return(testProvider.Instances, nil) os.Setenv("RACK", "convox-test") os.Setenv("CLUSTER", "convox-test-cluster") aws := test.StubAws( test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackCycle("convox-test-myapp-staging"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.ListContainerInstancesCycle("convox-test-cluster"), test.DescribeContainerInstancesCycle("convox-test-cluster"), test.DescribeInstancesCycle(), test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"), test.DescribeTasksCycle("convox-test-cluster"), test.ListTasksOneoffEmptyCycle("convox-test-cluster"), test.DescribeTaskDefinitionCycle("convox-test-cluster"), test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"), test.DescribeServicesCycle("convox-test-cluster"), ) defer aws.Close() docker := test.StubDocker( // query for every ECS task to get docker id, command, created test.ListECSContainersCycle(), // query every instance for one-off containers test.ListOneoffContainersEmptyCycle(), test.ListOneoffContainersCycle("79bd711b1756"), test.InspectCycle("79bd711b1756"), test.ListOneoffContainersEmptyCycle(), ) defer docker.Close() body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", url.Values{}) var resp client.Processes err := json.Unmarshal([]byte(body), &resp) if assert.Nil(t, err) { assert.Equal(t, 2, len(resp)) assert.Equal(t, "/bin/sh -c bash", resp[0].Command) assert.Equal(t, "echo 1", resp[1].Command) } }