github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/runtime/local/local_test.go (about)

     1  // Licensed under the Apache License, Version 2.0 (the "License");
     2  // you may not use this file except in compliance with the License.
     3  // You may obtain a copy of the License at
     4  //
     5  //     https://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS,
     9  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  // See the License for the specific language governing permissions and
    11  // limitations under the License.
    12  //
    13  // Original source: github.com/micro/go-micro/v3/runtime/local/local_test.go
    14  
    15  package local
    16  
    17  import (
    18  	"os"
    19  	"path/filepath"
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  )
    24  
    25  func TestEntrypoint(t *testing.T) {
    26  	wd, _ := os.Getwd()
    27  
    28  	// test a service with a single .mu file
    29  	result, err := Entrypoint(filepath.Join(wd, "test/bar"))
    30  	assert.Nil(t, err, "Didn'expected entrypoint to return an error")
    31  	assert.Equal(t, "bar.mu", result, "Expected entrypoint to return bar.mu")
    32  
    33  	// test a service with multiple .mu files within the cmd folder
    34  	result, err = Entrypoint(filepath.Join(wd, "test/foo"))
    35  	assert.Error(t, err, "Expected entrypoint to return an error when multiple .mu files exist")
    36  	assert.Equal(t, "", result, "Expected entrypoint to not return a result")
    37  
    38  	// test a service with no .mu or main.go files
    39  	result, err = Entrypoint(filepath.Join(wd, "test/empty"))
    40  	assert.Error(t, err, "Expected entrypoint to return an error when no .mu files exist and no main.go files exist")
    41  	assert.Equal(t, "", result, "Expected entrypoint to not return a result")
    42  
    43  	// test a service with idiomatic folder structure and no .mu file
    44  	result, err = Entrypoint(filepath.Join(wd, "test/qux"))
    45  	assert.Nil(t, err, "Didn't expecte entrypoint to return an error")
    46  	assert.Equal(t, "cmd/test/main.go", result, "Expected entrypoint to return cmd/test/main.go")
    47  }