Example #1
0
      it("should serialize encrypted value as value when updated", () => {
        const clusterProfile = new ClusterProfile(
          "docker1",
          "cd.go.docker",
          new Configurations([
                               new Configuration("image", new PlainTextValue("gocd/server")),
                               new Configuration("secret", new EncryptedValue("alskdad"))
                             ]));

        clusterProfile.properties().setConfiguration("secret", "foo");

        expect(JSON.parse(JSON.stringify(clusterProfile.toJSON()))).toEqual({
                                                                              id: "docker1",
                                                                              plugin_id: "cd.go.docker",
                                                                              properties: [{
                                                                                key: "image",
                                                                                value: "gocd/server"
                                                                              },
                                                                                {
                                                                                  key: "secret",
                                                                                  value: "foo"
                                                                                }
                                                                              ]
                                                                            });

      });
Example #2
0
 it("should validate cluster profile id format", () => {
   const clusterProfile = new ClusterProfile("invalid id", "pluginId", new Configurations([]));
   expect(clusterProfile.isValid()).toBe(false);
   expect(clusterProfile.errors().count()).toBe(1);
   expect(clusterProfile.errors().keys()).toEqual(["id"]);
   expect(clusterProfile.errors().errors("id"))
     .toEqual(["Invalid Id. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period)."]);
 });
  it("should update a cluster profile", (done) => {
    jasmine.Ajax.stubRequest(GET_CLUSTER_PROFILE_PATH).andReturn(clusterProfileResponse());

    const onResponse = jasmine.createSpy().and.callFake((response: ApiResult<any>) => {
      const responseJSON = response.unwrap() as SuccessResponse<any>;
      expect(responseJSON.body.object.id()).toEqual("cluster_1");
      expect(responseJSON.body.object.pluginId()).toEqual("plugin_1");
      expect(response.getEtag()).toEqual("some-etag");
      done();
    });

    ClusterProfilesCRUD.update(ClusterProfile.fromJSON(clusterProfileTestData("cluster_1", "plugin_2")), "old_etag")
                       .then(onResponse);

    const request = jasmine.Ajax.requests.mostRecent();
    expect(request.url).toEqual(GET_CLUSTER_PROFILE_PATH);
    expect(request.method).toEqual("PUT");
    expect(request.requestHeaders.Accept).toEqual("application/vnd.go.cd.v1+json");
  });
Example #4
0
      it("should deserialize cluster profile", () => {
        const clusterProfile = ClusterProfile.fromJSON({
                                                         id: "docker1",
                                                         plugin_id: "cd.go.docker",
                                                         properties: [{
                                                           key: "image",
                                                           value: "gocd/server",
                                                           encrypted_value: null
                                                         },
                                                           {
                                                             key: "memory",
                                                             value: "10M",
                                                             encrypted_value: null
                                                           }
                                                         ]
                                                       });

        expect(clusterProfile.id()).toEqual("docker1");
        expect(clusterProfile.pluginId()).toEqual("cd.go.docker");
        expect(clusterProfile.properties().count()).toBe(2);
        expect(clusterProfile.properties().valueFor("image")).toEqual("gocd/server");
        expect(clusterProfile.properties().valueFor("memory")).toEqual("10M");
      });
Example #5
0
 it("should validate cluster profile", () => {
   const clusterProfile = new ClusterProfile("", "", new Configurations([]));
   expect(clusterProfile.isValid()).toBe(false);
   expect(clusterProfile.errors().count()).toBe(2);
   expect(clusterProfile.errors().keys().sort()).toEqual(["id", "pluginId"]);
 });