Example #1
0
func TestGetComponents(t *testing.T) {
	const componentRoute = "/components"
	resp, apiServer, err := testGet(componentRoute)
	if apiServer != nil {
		apiServer.Close()
	}
	assert.NoErr(t, err)
	assert200(t, resp)
	respData, err := ioutil.ReadAll(resp.Body)
	assert.NoErr(t, err)
	cluster, err := data.ParseJSONCluster(respData)
	assert.NoErr(t, err)
	mockData, err := mocks.GetMockCluster()
	assert.NoErr(t, err)
	mockCluster, err := data.ParseJSONCluster(mockData)
	assert.NoErr(t, err)
	assert.Equal(t, cluster.ID, mockCluster.ID, "cluster ID value")
	for i, component := range cluster.Components {
		assert.Equal(t, component.Component, mockCluster.Components[i].Component, "component type")
		assert.Equal(t, component.Version, mockCluster.Components[i].Version, "version type")
		_, err := mocks.GetMockLatest(component.Component.Name)
		assert.NoErr(t, err)
		// TODO add tests for UpdateAvailable field
	}
}
Example #2
0
func TestComponentsHandler(t *testing.T) {
	componentsHandler := ComponentsHandler(
		mockInstalledComponents{},
		&mockClusterID{},
		mockAvailableVersion{},
	)
	resp, err := getTestHandlerResponse(componentsHandler)
	assert.NoErr(t, err)
	assert200(t, resp)
	respData, err := ioutil.ReadAll(resp.Body)
	assert.NoErr(t, err)
	cluster, err := data.ParseJSONCluster(respData)
	assert.NoErr(t, err)
	assert.Equal(t, cluster.ID, mockID, "ID value")
	assert.Equal(t, cluster.Components[0].Component.Name, mockInstalledComponentName, "Name value")
	assert.Equal(t, *cluster.Components[0].Component.Description, mockInstalledComponentDescription, "Description value")
	assert.Equal(t, cluster.Components[0].Version.Version, mockInstalledComponentVersion, "Version value")
	//TODO
	//assert.Equal(t, cluster.Components[0].UpdateAvailable, mockAvailableComponentVersion, "available Version value")
}