github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/transforms/xlang/inference/inference_test.go (about)

     1  // Licensed to the Apache Software Foundation (ASF) under one or more
     2  // contributor license agreements.  See the NOTICE file distributed with
     3  // this work for additional information regarding copyright ownership.
     4  // The ASF licenses this file to You under the Apache License, Version 2.0
     5  // (the "License"); you may not use this file except in compliance with
     6  // the License.  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  package inference
    17  
    18  import (
    19  	"flag"
    20  	"log"
    21  	"testing"
    22  
    23  	"github.com/apache/beam/sdks/v2/go/pkg/beam"
    24  	_ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/dataflow"
    25  	_ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/flink"
    26  	_ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/universal"
    27  	"github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest"
    28  	"github.com/apache/beam/sdks/v2/go/test/integration"
    29  )
    30  
    31  var expansionAddr string // Populate with expansion address labelled "python_transform".
    32  
    33  func checkFlags(t *testing.T) {
    34  	if expansionAddr == "" {
    35  		t.Skip("No python transform expansion address provided.")
    36  	}
    37  }
    38  
    39  func TestSklearnInference(t *testing.T) {
    40  	integration.CheckFilters(t)
    41  	checkFlags(t)
    42  	p := SklearnInference(expansionAddr)
    43  	ptest.RunAndValidate(t, p)
    44  }
    45  
    46  func TestMain(m *testing.M) {
    47  	flag.Parse()
    48  	beam.Init()
    49  
    50  	services := integration.NewExpansionServices()
    51  	defer func() { services.Shutdown() }()
    52  	addr, err := services.GetAddr("python_transform")
    53  	if err != nil {
    54  		log.Printf("skipping missing expansion service: %v", err)
    55  	} else {
    56  		expansionAddr = addr
    57  	}
    58  
    59  	ptest.MainRet(m)
    60  }