github.com/pelicanplatform/pelican@v1.0.5/cmd/plugin_test.go (about)

     1  /***************************************************************
     2   *
     3   * Copyright (C) 2023, University of Nebraska-Lincoln
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License"); you
     6   * may not use this file except in compliance with the License.  You may
     7   * obtain a copy of the License at
     8   *
     9   *    http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   ***************************************************************/
    18  
    19  package main
    20  
    21  import (
    22  	"bufio"
    23  	"strings"
    24  	"testing"
    25  
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  // TestReadMultiTransfer test if we can read multiple transfers from stdin
    30  func TestReadMultiTransfer(t *testing.T) {
    31  	t.Parallel()
    32  
    33  	// Test with multiple transfers
    34  	stdin := "[ LocalFileName = \"/path/to/local/copy/of/foo\"; Url = \"url://server/some/directory//foo\" ]\n[ LocalFileName = \"/path/to/local/copy/of/bar\"; Url = \"url://server/some/directory//bar\" ]\n[ LocalFileName = \"/path/to/local/copy/of/qux\"; Url = \"url://server/some/directory//qux\" ]"
    35  	transfers, err := readMultiTransfers(*bufio.NewReader(strings.NewReader(stdin)))
    36  	assert.NoError(t, err)
    37  	assert.Equal(t, 3, len(transfers))
    38  	assert.Equal(t, "/path/to/local/copy/of/foo", transfers[0].localFile)
    39  	assert.Equal(t, "url://server/some/directory//foo", transfers[0].url)
    40  	assert.Equal(t, "/path/to/local/copy/of/bar", transfers[1].localFile)
    41  	assert.Equal(t, "url://server/some/directory//bar", transfers[1].url)
    42  	assert.Equal(t, "/path/to/local/copy/of/qux", transfers[2].localFile)
    43  	assert.Equal(t, "url://server/some/directory//qux", transfers[2].url)
    44  
    45  	// Test with single transfers
    46  	stdin = "[ LocalFileName = \"/path/to/local/copy/of/blah\"; Url = \"url://server/some/directory//blah\" ]"
    47  	transfers, err = readMultiTransfers(*bufio.NewReader(strings.NewReader(stdin)))
    48  	assert.NoError(t, err)
    49  	assert.Equal(t, 1, len(transfers))
    50  	assert.Equal(t, "url://server/some/directory//blah", transfers[0].url)
    51  	assert.Equal(t, "/path/to/local/copy/of/blah", transfers[0].localFile)
    52  }