(t *testing.T)
| 846 | } |
| 847 | |
| 848 | func TestUpdateNetworks(t *testing.T) { |
| 849 | ctx := context.Background() |
| 850 | nws := []network.Summary{ |
| 851 | { |
| 852 | Network: network.Network{ |
| 853 | Name: "aaa-network", |
| 854 | ID: "id555", |
| 855 | }, |
| 856 | }, |
| 857 | { |
| 858 | Network: network.Network{ |
| 859 | Name: "mmm-network", |
| 860 | ID: "id999", |
| 861 | }, |
| 862 | }, |
| 863 | { |
| 864 | Network: network.Network{ |
| 865 | Name: "zzz-network", |
| 866 | ID: "id111", |
| 867 | }, |
| 868 | }, |
| 869 | } |
| 870 | |
| 871 | apiClient := &fakeClient{ |
| 872 | networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error) { |
| 873 | for _, nw := range nws { |
| 874 | if nw.ID == networkID || nw.Name == networkID { |
| 875 | return client.NetworkInspectResult{ |
| 876 | Network: network.Inspect{Network: nw.Network}, |
| 877 | }, nil |
| 878 | } |
| 879 | } |
| 880 | return client.NetworkInspectResult{}, fmt.Errorf("network not found: %s", networkID) |
| 881 | }, |
| 882 | } |
| 883 | |
| 884 | svc := swarm.ServiceSpec{ |
| 885 | TaskTemplate: swarm.TaskSpec{ |
| 886 | ContainerSpec: &swarm.ContainerSpec{}, |
| 887 | Networks: []swarm.NetworkAttachmentConfig{ |
| 888 | {Target: "id999"}, |
| 889 | }, |
| 890 | }, |
| 891 | } |
| 892 | |
| 893 | flags := newUpdateCommand(nil).Flags() |
| 894 | err := flags.Set(flagNetworkAdd, "aaa-network") |
| 895 | assert.NilError(t, err) |
| 896 | err = updateService(ctx, apiClient, flags, &svc) |
| 897 | assert.NilError(t, err) |
| 898 | assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)) |
| 899 | |
| 900 | flags = newUpdateCommand(nil).Flags() |
| 901 | err = flags.Set(flagNetworkAdd, "aaa-network") |
| 902 | assert.NilError(t, err) |
| 903 | err = updateService(ctx, apiClient, flags, &svc) |
| 904 | assert.Error(t, err, "service is already attached to network aaa-network") |
| 905 | assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)) |
nothing calls this directly
no test coverage detected
searching dependent graphs…