go.ligato.io/vpp-agent/v3@v3.5.0/tests/e2e/101_rest_api_test.go (about)

     1  //  Copyright (c) 2020 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package e2e
    16  
    17  import (
    18  	"context"
    19  	"encoding/json"
    20  	"io"
    21  	"testing"
    22  
    23  	. "github.com/onsi/gomega"
    24  
    25  	. "go.ligato.io/vpp-agent/v3/tests/e2e/e2etest"
    26  )
    27  
    28  func TestInfoVersionHandler(t *testing.T) {
    29  	ctx := Setup(t)
    30  	defer ctx.Teardown()
    31  
    32  	version, err := ctx.Agent.Client().AgentVersion(context.Background())
    33  	ctx.Expect(err).ToNot(HaveOccurred())
    34  	ctx.Expect(version.App).ToNot(BeEmpty())
    35  	ctx.Expect(version.Version).ToNot(BeEmpty())
    36  	ctx.Expect(version.GitCommit).ToNot(BeEmpty())
    37  	ctx.Expect(version.GitBranch).ToNot(BeEmpty())
    38  	ctx.Expect(version.BuildUser).ToNot(BeEmpty())
    39  	ctx.Expect(version.BuildHost).ToNot(BeEmpty())
    40  	ctx.Expect(version.BuildTime).ToNot(BeZero())
    41  	ctx.Expect(version.GoVersion).ToNot(BeEmpty())
    42  	ctx.Expect(version.OS).ToNot(BeEmpty())
    43  	ctx.Expect(version.Arch).ToNot(BeEmpty())
    44  }
    45  
    46  func TestJsonschema(t *testing.T) {
    47  	ctx := Setup(t)
    48  	defer ctx.Teardown()
    49  
    50  	res, err := ctx.Agent.Client().HTTPClient().Get("http://" + ctx.Agent.Client().AgentHost() + ":9191/info/configuration/jsonschema")
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	body, err := io.ReadAll(res.Body)
    55  	res.Body.Close()
    56  	if res.StatusCode > 299 {
    57  		t.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body)
    58  	}
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  	t.Logf("BODY: %s", body)
    63  
    64  	var data map[string]interface{}
    65  	if err := json.Unmarshal(body, &data); err != nil {
    66  		t.Fatal(err)
    67  	}
    68  }