github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/server/server_test.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package server
    18  
    19  import (
    20  	"fmt"
    21  	"net"
    22  	"testing"
    23  
    24  	"google.golang.org/grpc"
    25  
    26  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
    27  	"github.com/GoogleContainerTools/skaffold/proto/v1"
    28  	"github.com/GoogleContainerTools/skaffold/testutil"
    29  )
    30  
    31  var (
    32  	rpcAddr  = 12345
    33  	httpAddr = 23456
    34  )
    35  
    36  func TestServerStartup(t *testing.T) {
    37  	// start up servers
    38  	shutdown, err := Initialize(config.SkaffoldOptions{
    39  		EnableRPC:   true,
    40  		RPCPort:     config.NewIntOrUndefined(&rpcAddr),
    41  		RPCHTTPPort: config.NewIntOrUndefined(&httpAddr),
    42  	})
    43  	defer shutdown()
    44  	testutil.CheckError(t, false, err)
    45  
    46  	// create gRPC client and ensure we can connect
    47  	conn, err := grpc.Dial(fmt.Sprintf(":%d", rpcAddr), grpc.WithInsecure())
    48  	if err != nil {
    49  		t.Errorf("unable to establish skaffold grpc connection")
    50  	}
    51  	defer conn.Close()
    52  
    53  	client := proto.NewSkaffoldServiceClient(conn)
    54  	if client == nil {
    55  		t.Errorf("unable to connect to gRPC server")
    56  	}
    57  
    58  	// dial httpAddr and make sure port is being served on
    59  	httpConn, err := net.Dial("tcp", fmt.Sprintf(":%d", httpAddr))
    60  	if err != nil {
    61  		t.Errorf("unable to connect to gRPC HTTP server")
    62  	}
    63  	if httpConn == nil {
    64  		t.Errorf("unable to connect to gRPC HTTP server")
    65  	} else {
    66  		httpConn.Close()
    67  	}
    68  }