sudo: required
dist: trusty
env:
    global:
        - TARGET=iqn.2016-09.com.gotgt.gostor:example_tgt_0
    matrix:
        - TGT_CFG='{"storages":[{"deviceID":1000,"path":"file:/var/tmp/disk.img","online":true}],"iscsiportals":[{"id":0,"portal":"127.0.0.1:3260"}],"iscsitargets":{"iqn.2016-09.com.gotgt.gostor:example_tgt_0":{"tpgts":{"1":[0]},"luns":{"0":1000}}}}'
        - TGT_CFG='{"storages":[{"deviceID":1000,"path":"ceph-rbd:iscsi_pool/lun0","online":true}],"iscsiportals":[{"id":0,"portal":"127.0.0.1:3260"}],"iscsitargets":{"iqn.2016-09.com.gotgt.gostor:example_tgt_0":{"tpgts":{"1":[0]},"luns":{"0":1000}}}}'

language: go

go:
    - "1.10"
    - "1.11"
    - "1.12"

install:
   - true

before_script:
    - echo ${TGT_CFG}
    - echo ${TARGET}
    - sudo apt-get update
    - ci/ceph_install.sh
    - bash ci/ceph_micro-osd.sh /tmp/micro-ceph
    - export CEPH_CONF=/tmp/micro-ceph/ceph.conf
    - ceph status
    - sudo apt-get install -y libcunit1 libcunit1-doc libcunit1-dev
    - sudo apt-get install -y open-iscsi

script:
   - cd ${TRAVIS_BUILD_DIR}
   # Try a build without cgo first
   - make build-nocgo
   - make clean
   # Now build with cgo and cephstore.
   - make
   - hack/verify-gofmt.sh
   - go test -v ./pkg/...
   - dd if=/dev/zero of=/var/tmp/disk.img bs=1024 count=102400
   - mkdir ${HOME}/.gotgt
   - echo ${TGT_CFG} > ${HOME}/.gotgt/config.json
   - ./_output/cmd/bin/gotgt daemon --log debug 1>/dev/null 2>&1 &
   # libiscsi test
   - mkdir ${HOME}/libiscsi
   - git clone https://github.com/gostor/libiscsi ${HOME}/libiscsi
   - cd ${HOME}/libiscsi
   - export ISCSITEST=yes
   - ./autogen.sh
   - ./configure 2>&1 >/dev/null
   - make 2>&1 >/dev/null
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.Standard iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.AllocLength iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.MandatoryVPDSBC iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.SupportedVPD iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.VersionDescriptors iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Inquiry.EVPD iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Mandatory iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.ModeSense6 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.NoMedia iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Prefetch10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Prefetch16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.PreventAllow iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.ReadCapacity10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.ReadCapacity16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Read6 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Read10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Read12 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Read16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.ReadOnly iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.ReportSupportedOpcodes.Simple iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Reserve6.Simple iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.StartStopUnit iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.TestUnitReady iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Write10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Write16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Write12 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteVerify12 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteSame10.Simple iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.WriteSame16.Simple iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Verify10 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Verify12 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.Verify16 iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.iSCSITMF iscsi://127.0.0.1:3260/${TARGET}/0
   - ./test-tool/iscsi-test-cu -d -A --test=ALL.iSCSIcmdsn iscsi://127.0.0.1:3260/${TARGET}/0

   - ./utils/iscsi-ls -s iscsi://127.0.0.1:3260/${TARGET}
   - ./utils/iscsi-inq iscsi://127.0.0.1:3260/${TARGET}/0
   - ./utils/iscsi-readcapacity16 iscsi://127.0.0.1:3260/${TARGET}/0
   # iscsi initiator test
   - sudo iscsiadm -m discovery -t sendtargets -p 127.0.0.1
   - sudo iscsiadm -m node -L all
   - sudo iscsiadm -m session
   - sudo fdisk -l
   - echo -e "n\np\n1\n\n\nt\nc\na\n1\nw" | sudo fdisk /dev/sdb
   - sudo mkfs.ext3 /dev/sdb1
   - sudo mkdir -p /var/tmp/test
   - sudo mount /dev/sdb1 /var/tmp/test
   - sudo ls -lh /var/tmp/test/

